package com.sixkey.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sixkey.entity.Evaluation;
import com.sixkey.entity.User;
import com.sixkey.entity.vo.EvaluationVo;
import com.sixkey.mapper.EvaluationMapper;
import com.sixkey.service.IEvaluationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sixkey.service.IUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 用户评价表 服务实现类
 * </p>
 *
 * @author author
 * @since 2023-10-18
 */
@Service
@RequiredArgsConstructor
public class EvaluationServiceImpl extends ServiceImpl<EvaluationMapper, Evaluation> implements IEvaluationService {

    /**
     * 小程序端查询用户评价
     * @param
     * @return
     */
    @Override
    public List<Evaluation> getEvaluation() {
        List<Evaluation> list = this.list();
        return list;
    }

    /**
     * 后台分页查询用户评价
     * @param
     * @return
     */
    @Override
    public Page<Evaluation> queryList(Integer pageNo, Integer pageSize, EvaluationVo evaluationVo) {
        Page<Evaluation> pageInfo = new Page<>(pageNo, pageSize);
        LambdaQueryWrapper<Evaluation> wrapper = new LambdaQueryWrapper<>();
        //添加过滤条件(模糊查询)
        wrapper.like(!StringUtils.isEmpty(evaluationVo.getPhone()),Evaluation::getPhone,evaluationVo.getPhone());
        wrapper.like(!StringUtils.isEmpty(evaluationVo.getGrade()),Evaluation::getGrade,evaluationVo.getGrade());
        //添加排序条件
        wrapper.orderByDesc(Evaluation::getUpdateTime);
        Page<Evaluation> userPage = this.page(pageInfo, wrapper);
        return userPage;
    }
}
